package com.ruoyi.api.mail;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Dto.JiajiaMallOrderDto;
import com.ruoyi.system.domain.JiajiaMallOrder;
import com.ruoyi.system.domain.vo.JiajiaMallOrderVo;
import com.ruoyi.system.service.IJiajiaMallOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城订单Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/api/mall/order")
public class ApiJiajiaMallOrderController
{
    private String prefix = "mall/order";

    @Autowired
    private IJiajiaMallOrderService jiajiaMallOrderService;

    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询商城订单列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(JiajiaMallOrderDto jiajiaMallOrder)
    {
        List<JiajiaMallOrderVo> list = jiajiaMallOrderService.selectJiajiaMallOrderList(jiajiaMallOrder);
        return AjaxResult.success(list);
    }

    /**
     * 导出商城订单列表
     */
    @Log(title = "商城订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMallOrderDto jiajiaMallOrder)
    {
        List<JiajiaMallOrderVo> list = jiajiaMallOrderService.selectJiajiaMallOrderList(jiajiaMallOrder);
        ExcelUtil<JiajiaMallOrderVo> util = new ExcelUtil<JiajiaMallOrderVo>(JiajiaMallOrderVo.class);
        return util.exportExcel(list, "商城订单数据");
    }

    /**
     * 新增商城订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城订单
     */
    @Log(title = "商城订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody JiajiaMallOrderDto jiajiaMallOrder)
    {

        return AjaxResult.success(jiajiaMallOrderService.insertJiajiaMallOrder(jiajiaMallOrder));
    }

    /**
     * 修改商城订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMallOrderVo jiajiaMallOrder = jiajiaMallOrderService.selectJiajiaMallOrderById(id);
        mmap.put("jiajiaMallOrder", jiajiaMallOrder);
        return prefix + "/edit";
    }




    /**
     * 修改保存商城订单
     */
    @Log(title = "商城订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave( JiajiaMallOrder jiajiaMallOrder)
    {
        return AjaxResult.success(jiajiaMallOrderService.updateJiajiaMallOrder(jiajiaMallOrder));
    }


    /**
     * 修改订单状态
     */
    @Log(title = "商城订单", businessType = BusinessType.UPDATE)
    @PostMapping("/editOrderStatus")
    @ResponseBody
    public AjaxResult editOrderStatus( JiajiaMallOrderDto jiajiaMallOrderDto)
    {
        return AjaxResult.success(jiajiaMallOrderService.updateJiajiaMallOrderStatus(jiajiaMallOrderDto));
    }






    /**
     * 删除商城订单
     */
    @Log(title = "商城订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(jiajiaMallOrderService.deleteJiajiaMallOrderByIds(ids));
    }
}
